﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WLCompiler.Helpers.ListOperations
{
    public static class ListOperations
    {
        public static void PrintList(List<int> list)
        {
            foreach (var v in list)
            {
                Console.Write(v);
                Console.Write(" ");
            }

            Console.Write(Environment.NewLine);
        }

        public static int ElementAt(List<int> list, int index)
        {
            return list.ElementAt(index);
        }

        public static int Contains(List<int> list, int value)
        {
            return list.Contains(value) ? 1 : -1;
        }

        public static int IndexOf(List<int> list, int value)
        {
            return list.IndexOf(value);
        }

        public static int Count(List<int> list)
        {
            return list.Count();
        }

        public static int Sum(List<int> list)
        {
            return !list.Any() ? 0 : list.Aggregate((result, next) => result + next);
        }

        public static int Mult(List<int> list)
        {
            return !list.Any() ? 0 : list.Aggregate((result, next) => result * next);
        }

        public static List<int> ReadList()
        {
            var listStr = Console.ReadLine();
            var valArray = listStr == null ? new string[] { } : listStr.Split(new[] { ' ' });

            return valArray.Select(int.Parse).ToList();
        }
    }
}
